export const getNowFormatDate = (date = new Date()) => {
	//TODO 格式化当前时间
	const year = date.getFullYear();
	const month = (date.getMonth() + 1).toString().padStart(2, '0'); // 月份从 0 开始，所以需要加 1
	const day = date.getDate().toString().padStart(2, '0');
	const hours = date.getHours().toString().padStart(2, '0');
	const minutes = date.getMinutes().toString().padStart(2, '0');
	const seconds = date.getSeconds().toString().padStart(2, '0');

	return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
export const formatDate = (format) => {
	const now = new Date();
	const year = now.getFullYear();
	const month = String(now.getMonth() + 1).padStart(2, '0'); // 月份从0开始，+1后格式化
	const day = String(now.getDate()).padStart(2, '0');
	const hours = String(now.getHours()).padStart(2, '0');
	const minutes = String(now.getMinutes()).padStart(2, '0');
	const seconds = String(now.getSeconds()).padStart(2, '0');

	// 替换格式中的标记
	return format
		.replace('yyyy', year)
		.replace('mm', month)
		.replace('dd', day)
		.replace('hh', hours)
		.replace('mm', minutes)
		.replace('ss', seconds);
}
export const calculateAge = (birthDate) => {

	const today = new Date(); // 获取当前日期
	const birth = new Date(birthDate); // 将传入的出生日期字符串转换为日期对象

	let age = today.getFullYear() - birth.getFullYear(); // 计算年差

	// 检查是否已经过了生日，如果没有过，则减去 1
	const monthDiff = today.getMonth() - birth.getMonth();
	if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birth.getDate())) {
		age--;
	}

	return age || 0;

}